package com.qy.mybatisplus.util;


import lombok.Data;

/**
 * @program:
 * @description:
 * @author: Mr.Huang
 * @create: 2019-06-24 16:21
 **/
@Data
public class Result<T> {

    private int resultCode = 200;

    private String message = "SUCCESS";

    private T data;

    public Result() {}

    public static Result build() {
        return new Result();
    }

    public static Result ok(String msg, Object obj) {
        return new Result(200, msg, obj);
    }

    public static Result ok(String msg) {
        return new Result(200, msg, null);
    }

    public static Result error(String msg, Object obj) {
        return new Result(500, msg, obj);
    }

    public static Result error(String msg) {
        return new Result(500, msg, null);
    }

    /**
     * 只返回错误码
     *
     * @param resultCode resultCode
     */
    public Result(int resultCode) {
        this.resultCode = resultCode;
    }

    /**
     * 只有返回数据的(验证成功)
     *
     * @param data data
     */
    public Result(T data) {
        this.data = data;
    }

    /**
     * 只有错误码和错误信息的
     *
     * @param resultCode resultCode
     * @param message    message
     */
    public Result(int resultCode, String message) {
        this.resultCode = resultCode;
        this.message = message;
    }


    /**
     * 全部参数
     *
     * @param resultCode resultCode
     * @param message    message
     * @param data       data
     */
    public Result(int resultCode, String message, T data) {
        this.resultCode = resultCode;
        this.message = message;
        this.data = data;
    }
}
